package com.example.myapplication.adapter;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.example.myapplication.FirstHomeFragment;
import com.example.myapplication.SecondHomeFragment;
import com.example.myapplication.ThreeHomeFragment;

import java.util.HashMap;
import java.util.Map;
public class HomeVpAdapter extends FragmentPagerAdapter {

    private Map<Integer,Fragment> data;

    public HomeVpAdapter(@NonNull FragmentManager fm) {
        super(fm);
        data = new HashMap<>();
        data.put(0,new FirstHomeFragment());
        data.put(1,new SecondHomeFragment());
        data.put(2,new ThreeHomeFragment());
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        return data.get(position);
    }

    @Override
    public int getCount() {
        return 3;
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        switch (position){
            case 0:
                return "首页";
            case 1:
                return "新闻";
            case 2:
                return "设置";
        }
        return "";
    }
}
